package com.qf.web;

import com.qf.pojo.User;
import com.qf.service.UserService;
import com.qf.service.serviceimpl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
/**
 * 查找所有用户
 * */
@WebServlet("/findAllUser")
public class FinfAllUserServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");//处理post提交乱码
        response.setContentType("text/html;charset=utf-8");
        UserService us = new UserServiceImpl(); //调用业务层代码获取数据
        List<User> user = us.findAllUser();
        if(user != null){
            HttpSession session = request.getSession();
            session.setAttribute("user",user);
            request.getRequestDispatcher("/admin/findall.jsp").forward(request,response);
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
